using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HHF.Models;

namespace HHF.Controllers
{
    [AuthorizeAdmin]
    public class PagesAdminController : Controller
    {
		private readonly ICmsItemRepository cmsitemRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PagesAdminController() : this(new CmsItemRepository())
        {
        }

        public PagesAdminController(ICmsItemRepository cmsitemRepository)
        {
			this.cmsitemRepository = cmsitemRepository;
        }

        //
        // GET: /PagesAdmin/

        public ViewResult Index()
        {
            return View(cmsitemRepository.All);
        }

        //
        // GET: /PagesAdmin/Details/5

        public ViewResult Details(int id)
        {
            return View(cmsitemRepository.Find(id));
        }

        //
        // GET: /PagesAdmin/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PagesAdmin/Create

        [HttpPost]
        public ActionResult Create(CmsItem cmsitem)
        {
            if (ModelState.IsValid) {
                cmsitemRepository.InsertOrUpdate(cmsitem);
                cmsitemRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /PagesAdmin/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(cmsitemRepository.Find(id));
        }

        //
        // POST: /PagesAdmin/Edit/5

        [HttpPost]
        public ActionResult Edit(CmsItem cmsitem)
        {
            if (ModelState.IsValid) {
                cmsitemRepository.InsertOrUpdate(cmsitem);
                cmsitemRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /PagesAdmin/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(cmsitemRepository.Find(id));
        }

        //
        // POST: /PagesAdmin/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            cmsitemRepository.Delete(id);
            cmsitemRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

